<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>将字符串的首字母转换为大写</title>
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-base.css" />
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-medium.css" />

 </head>
 <body class="docs"><div class="navbar navbar-fixed-top">
  <div class="navbar-inner clearfix">
    <ul class="nav" style="width: 100%">
      <li style="float: left;"><a href="function.trim.html">« trim</a></li>
      <li style="float: right;"><a href="function.ucwords.html">ucwords »</a></li>
    </ul>
  </div>
</div>
<div id="breadcrumbs" class="clearfix">
  <ul class="breadcrumbs-container">
    <li><a href="index.html">PHP Manual</a></li>
    <li><a href="ref.strings.html">字符串 函数</a></li>
    <li>将字符串的首字母转换为大写</li>
  </ul>
</div>
<div id="layout">
  <div id="layout-content"><div id="function.ucfirst" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">ucfirst</h1>
  <p class="verinfo">(PHP 4, PHP 5, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">ucfirst</span> &mdash; <span class="dc-title">将字符串的首字母转换为大写</span></p>

 </div>
 
 <div class="refsect1 description" id="refsect1-function.ucfirst-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>ucfirst</strong></span>(<span class="methodparam"><span class="type">string</span> <code class="parameter">$string</code></span>): <span class="type">string</span></div>

  <p class="para rdfs-comment">
   将 <code class="parameter">string</code> 的首字符（如果首字符是 <code class="literal">&quot;a&quot;</code>（0x61）到
   <code class="literal">&quot;z&quot;</code>（0x7a）范围内的 ASCII 字符）转换为大写字母，并返回这个字符串。
  </p>
  <p class="para">
   注意字母的定义取决于当前区域设定。例如，在默认的 “C” 区域，字符 umlaut-a（ä）将不会被转换。
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.ucfirst-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>
    
     <dt>
<code class="parameter">string</code></dt>

     <dd>

      <p class="para">
       输入字符串。
      </p>
     </dd>

    
   </dl>

  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.ucfirst-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   返回结果字符串。
  </p>
 </div>


 <div class="refsect1 changelog" id="refsect1-function.ucfirst-changelog">
  <h3 class="title">更新日志</h3>
  <table class="doctable informaltable">
   
    <thead>
     <tr>
      <th>版本</th>
      <th>说明</th>
     </tr>

    </thead>

    <tbody class="tbody">
     
 <tr>
  <td>8.2.0</td>
  <td>
   大小写转换不在依赖于使用 <span class="function"><a href="function.setlocale.html" class="function">setlocale()</a></span> 设置的区域。只会转换 ASCII 字符。
  </td>
 </tr>


    </tbody>
   
  </table>

 </div>


 <div class="refsect1 examples" id="refsect1-function.ucfirst-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   <div class="example" id="example-4881">
    <p><strong>示例 #1 <span class="function"><strong>ucfirst()</strong></span> 范例</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$foo&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">'hello&nbsp;world!'</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$foo&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">ucfirst</span><span style="color: #007700">(</span><span style="color: #0000BB">$foo</span><span style="color: #007700">);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">//&nbsp;Hello&nbsp;world!<br /><br /></span><span style="color: #0000BB">$bar&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">'HELLO&nbsp;WORLD!'</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$bar&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">ucfirst</span><span style="color: #007700">(</span><span style="color: #0000BB">$bar</span><span style="color: #007700">);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">//&nbsp;HELLO&nbsp;WORLD!<br /></span><span style="color: #0000BB">$bar&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">ucfirst</span><span style="color: #007700">(</span><span style="color: #0000BB">strtolower</span><span style="color: #007700">(</span><span style="color: #0000BB">$bar</span><span style="color: #007700">));&nbsp;</span><span style="color: #FF8000">//&nbsp;Hello&nbsp;world!<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

   </div>   
  </p>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.ucfirst-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"><span class="function"><a href="function.lcfirst.html" class="function" rel="rdfs-seeAlso">lcfirst()</a> - 使字符串的第一个字符小写</span></li>
    <li class="member"><span class="function"><a href="function.strtolower.html" class="function" rel="rdfs-seeAlso">strtolower()</a> - 将字符串转化为小写</span></li>
    <li class="member"><span class="function"><a href="function.strtoupper.html" class="function" rel="rdfs-seeAlso">strtoupper()</a> - 将字符串转化为大写</span></li>
    <li class="member"><span class="function"><a href="function.ucwords.html" class="function" rel="rdfs-seeAlso">ucwords()</a> - 将字符串中每个单词的首字母转换为大写</span></li>
    <li class="member"><span class="function"><a href="function.mb-convert-case.html" class="function" rel="rdfs-seeAlso">mb_convert_case()</a> - 对字符串进行大小写转换</span></li>
   </ul>
  </p>
 </div>


</div></div></div></body></html>